<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改个人信息</title>
    <% include ../../common.ejs %>
    <link rel="stylesheet" type="text/css" href="../../stylesheets/xcConfirm.css"/>
    <script type="text/javascript" src="../../javascripts/xcConfirm.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../javascripts/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript" src="../../javascripts/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="../../javascripts/bootstrap-datetimepicker.zh-CN.js"></script>
    <script type="text/javascript">
        $(function () {
            $('.form_datetime').datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'zh-CN',
                minView: "month",
                autoclose: true
            });
        })

        var checkTel = function () {
            if ($("#tel").val() == "") {
                $("#msg2").empty();
                return false;
            }
            var tel = $("#tel").val(); //获取手机号
            var telReg = !!tel.match(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);
            //如果手机号码不能通过验证
            if (telReg == false) {
                $("#msg2").html("<img src='/images/icons/failure.png' style='height: 25px;width: 25px;'>");
                return false;
            } else {
                var tag = true;
                $.ajax({
                    type: 'post',
                    async: false,//同步提交
                    url: "/admin/personalSetting/checkTel",
                    data: {
                        param: tel,
                        id: <%= user.userInfoId%>,
                    },
                    success: function (e) {
                        if (e.code == 200) {
                            $("#msg2").html("<img src='/images/icons/failure.png' style='height: 25px;width: 25px;'>");
                            tag = false;
                        }
                        else {
                            $("#msg2").html("<img src='/images/icons/success.png' style='height: 25px;width: 25px;'>");
                        }
                    }
                });
                if (tag == false) {
                    return false;
                }
            }
        }

        var checkEmail = function () {
            if ($("#email").val() == "") {
                $("#msg3").empty();
                return false;
            }
            else {
                var email = $("#email").val();
                var tagEmail = !!email.match(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/);
                if (tagEmail == false) {
                    $("#msg3").html("<img src='/images/icons/failure.png' style='height: 25px;width: 25px;'>");
                    return false;
                } else {
                    $("#msg3").html("<img src='/images/icons/success.png' style='height: 25px;width: 25px;'>");
                }
            }
        }

        var checkAll = function () {
            if (checkTel() == false) {
                return false;
            }
            if (checkEmail() == false) {
                return false;
            }
        }
        function submitForm() {
            if (checkAll() == false) {
                return false;
            }
        }

        function alertSuccess() {
            var txt = "修改成功";
            window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.success);
        }
        ;

        function alertFail() {
            var txt = "抱歉，服务器繁忙！";
            window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.error);
        }
    </script>
    <style>
    </style>

</head>
<body>
<div id="top">
    <% include ../top.ejs %>
</div>
<div class="container-fluid" style="margin-top: 20px;">
    <div class="row">
        <div class="col-md-1">
        </div>
        <div id="left" class="col-md-2">
            <% include ../left.ejs %>
        </div>
        <div class="col-md-8 bodyDiv" id="right">

                <div class="row">
                    <div class="col-md-12">
                        <form class="form-horizontal" role="form" action="/admin/personalSetting/updatePersonInfo"
                              method="post"
                              onsubmit="return checkAll()">

                            <div class="row">
                                <div class="col-md-6">
                                    <span class="headTitle">修改个人信息</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <br/><br/><label for="inputEmail3" style="margin-left: 4cm"
                                                 class="col-sm-2 control-label">
                                    姓名：
                                </label>

                                <div class="col-sm-4">
                                    <input type="text" name="name" class="form-control" id="name"
                                           value="<%= user.name %>"/>

                                </div>
                                <div class="col-sm-1" id="msg1"></div>
                                性别：<INPUT type="radio" name="sex" checked value="M" <% if(user.sex == "M"){ %>checked
                                        <% } %>
                                        >男
                                <INPUT type="radio" name="sex" value="F" <% if(user.sex == "F"){ %>checked
                                        <% } %>
                                        >女
                            </div>

                            <div class="form-group">
                                <label for="inputEmail3" style="margin-left: 4cm" class="col-sm-2 control-label">
                                    手机号码：
                                </label>

                                <div class="col-sm-4">
                                    <input type="text" name="tel" class="form-control" id="tel" onblur="checkTel()"
                                           value="<%= user.tel %>">
                                </div>
                                <div class="col-sm-1" id="msg2"></div>
                            </div>

                            <div class="form-group">
                                <label for="inputEmail3" style="margin-left: 4cm" class="col-sm-2 control-label">
                                    邮箱：
                                </label>

                                <div class="col-sm-4">
                                    <input type="email" name="email" class="form-control" id="email"
                                           onblur="checkEmail()" value="<%= user.email %>"/>
                                </div>
                                <div class="col-sm-1" id="msg3"></div>
                            </div>

                            <div class="form-group">
                                <label for="inputEmail3" style="margin-left: 4cm" class="col-sm-2 control-label">
                                    生日：
                                </label>

                                <div class="col-sm-4">
                                    <input size="16" type="text" name="birthday" readonly
                                           class="form-control form_datetime" value="<%= user.birthday %>">
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="inputEmail3" style="margin-left: 4cm" class="col-sm-2 control-label">
                                    联系地址：
                                </label>

                                <div class="col-sm-7">
                                    <input type="text" name="address" class="form-control" id="inputEmail3"
                                           value="<%= user.address %>"/>
                                </div>
                            </div>


                            <div class="container-fluid">
                                <div class="row">
                                    <div class="col-md-3"></div>
                                    <div class="col-md-4" style="margin-left: 55px;margin-top: -15px;">
                                        <br/>
                                        &nbsp;&nbsp;&nbsp;
                                        <button type="submit" style="width: 180px;" class="btn btn-default"
                                                onclick="submitForm()">
                                            修改
                                        </button>
                                    </div>
                                    <div class="col-md-3" id="msg4" style="margin-top:5px;"></div>
                                </div>
                            </div>
                            <input type="hidden" name="id" value="<%= user.id %>">
                            <style>
                                .font_red {
                                    color: red;
                                    size: 2pt;
                                    font-size: 20px;
                                }

                                .font_green {
                                    color: green;
                                    size: 2pt;
                                    font-size: 20px;
                                }
                            </style>
                            <% if(users == 1){ %>
                            <% } %>
                            <% if(users != 1){ %>
                            <% if(users == 200){ %>
                            <script>
                                alertSuccess();
                                /*$("#msg4").show().html("<span class='font_green'>修改成功</span>");
                                 $("#msg4").delay(10000).hide(0);*/
                            </script>
                            <% } %>
                            <% if(users == 0){ %>
                            <script>
                                alertFail();
                                //$("#msg4").show().html("<span class='font_red'>修改失败，请注意提示信息</span>");
                            </script>
                            <% } %>
                            <% } %>
                        </form>
                    </div>
                </div>

            <!--内容-->
        </div>
        <div class="col-md-1">
        </div>
    </div>

</div>
<br/>

</body>
</html>